<?php

namespace app\admin\model;

use app\common\model\TimeModel;
use think\Exception;

class BuddhaOrder extends TimeModel
{

    protected $name = "buddha_order";

    protected $deleteTime = "delete_time";


    public function getPaymentList()
    {
        return ['0' => '未支付', '1' => '支付成功', '2' => '支付失败', '3' => '订单退款',];
    }

    public function getStatusList()
    {
        return ['0' => '禁用', '1' => '启用',];
    }

    /**
     * @param string $order_id
     * @return BuddhaOrder|array|mixed|\think\Model|null
     * @throws Exception
     */
    public function getOrderByTradeNo(string $order_id = "")
    {
        try {
            $order = $this->where('order_id', $order_id)
                ->find();
        } catch (\Exception $e) {
            throw new Exception("查询失败");
        }
        return $order;
    }

    protected function getGetCateAttr($value)
    {
        return (new BuddhaCate())->getBaseById($value);
    }

    protected function getGetPaymentTimeAttr($value)
    {
        if ($value == 0) {
            return "还未支付";
        }
        return date('Y-m-d H:i:s', $value);
    }
}